/**
 * 
 */
package org.youisoft.summer.evaluator.function.service;

import org.youisoft.summer.evaluator.InvokeException;
import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.function.AbstractFunction;
import org.youisoft.summer.evaluator.operator.Operator;
import org.youisoft.summer.evaluator.operator.base.MessageOperator;
import org.youisoft.summer.evaluator.operator.base.NullOperator;
import org.youisoft.summer.evaluator.operator.base.StringOperator;

/**
 * @author zijiang.jl
 *
 */
public class RouterFunction extends AbstractFunction{

	@Override
	protected boolean checkBracketOperator(int index, Operator<?> operator) {
		if(index==0&&StringOperator.class.isAssignableFrom(operator.getClass())) return true;
		if(index==1&&NullOperator.class.isAssignableFrom(operator.getClass())) return true;
		return false;
	}

	@Override
	protected boolean checkParenthesisOperator(int index, Operator<?> operator) {
		if(index==0&&StringOperator.class.isAssignableFrom(operator.getClass())) return true;
		if(index==1&&MessageOperator.class.isAssignableFrom(operator.getClass())) return true;
		return false;
	}
	
	@Override
	protected boolean checkAddendumOperator(Operator<?> operator) {
		return MessageOperator.class.isAssignableFrom(operator.getClass());
	}
	
	@Override
	public <C, R, P> Operator<?> doBracketInvoke(CalContext<C, R, P> context,
			Operator<?>... operator) throws InvokeException {
		return super.doBracketInvoke(context, operator);
	}

	@Override
	public <C, R, P> Operator<?> doParenthesisInvoke(CalContext<C, R, P> context,
			Operator<?>... operator) throws InvokeException {
		
		System.out.println("in RouterFunction");
		
		return operator[1];
	}
	
	

}
